package com.array.generate;

import java.lang.reflect.Constructor;

import com.generic.genericinterface.demo1.Generator;

public class GeneratorsTest {

	public static int size = 10;

	public static void test(Class<?> surroundingClass) throws Exception {
		for (Class<?> type : surroundingClass.getClasses()) {
			System.out.println(type.getName());
			Generator<?> gc = (Generator<?>) type.newInstance();
			for (int i = 0; i < size; i++) {
				System.out.print(gc.next() + " ");
			}
			System.out.println();
		}
	}

	public static void test2(Class<?> surroundingClass) throws Exception {
		for (Class<?> type : surroundingClass.getClasses()) {
			System.out.println(type.getSimpleName());
			// 查看class是否有构造函数
			System.out.println(type.getDeclaredConstructors().length);
			// 获取第一个构造函数
			Constructor c = type.getDeclaredConstructors()[0];
			Generator<?> gc = (Generator<?>) c
					.newInstance(new CountingGenerator2());
			for (int i = 0; i < size; i++) {
				System.out.print(gc.next() + " ");
			}
			System.out.println();
		}
	}

	public static void main(String[] args) throws Exception {
		test(CountingGenerator.class);
		System.out.println("===============================");
		test2(CountingGenerator2.class);
	}

}
